package com.system.manager.modules.risk.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.common.exception.SysException;
import com.system.manager.modules.authorized.entity.Role;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.risk.dto.RiskTypeVo;
import com.system.manager.modules.risk.dto.StaffStationVo;
import com.system.manager.modules.risk.entity.RiskType;
import com.system.manager.modules.risk.service.IRiskService;
import com.system.manager.modules.risk.service.IRiskTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-16
 */
@Api(tags = "风险类型")
@RestController
@RequestMapping("/risk/risk-type/")
public class RiskTypeController {

    @Autowired
    private IRiskTypeService iRiskTypeService;

    /**
     * 添加风险
     * @param riskTypeVo
     */
    @ApiOperation("系统管理员录入风险类型")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @PostMapping("addRiskType")
    public Result examList(@RequestBody RiskTypeVo riskTypeVo){
        iRiskTypeService.insert(riskTypeVo);
       /* UserDate<TbExam> exam = iTbExamService.findExam(subject);
        return new Result(exam.getCode(), exam.getMsg(),exam.getData(),exam.getCount());*/
        return Result.ok();
    }

    /**
     * 获取风险类型
     * @return
     */
    @ApiOperation("获取所有的风险类型")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @GetMapping("list")
    public Result riskTypeList() {
        try {
            // 获取所有的风险类型
            List<RiskType> list = iRiskTypeService.list();
            return Result.ok(list);

        } catch (Exception e) {
            e.printStackTrace();
            // 查询数据库出现异常
            return Result.error();
        }
    }

    /**
     * 删除风险类型
     */
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @ApiOperation("删除风险")
    @GetMapping("delete/{rtId}")
    public Result delete(@PathVariable("rtId")Integer rtId){

        try {
            iRiskTypeService.removeById(rtId);

            return Result.ok();
        } catch (SysException e) {
            e.printStackTrace();
            return Result.error(e);
        }

    }
}
